﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ImageK.Java.Extensions
{
    public static class PropertiesExtensions
    {
        public static void load(this Dictionary<string, string> props, string content)
        {
            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(content)))
            {
                try
                {
                    StreamReader reader = new StreamReader(ms);
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        string[] parts = line.Split('=');
                        if (parts.Length == 2)
                        {
                            props[parts[0]] = parts[1];
                        }
                    }
                }
                catch (IOException e)
                {
                    
                }
            }
        }

        public static string getProperty(this Dictionary<string, string> props, string key, string defaultValue)
        {
            return props.GetValueOrDefault(key, defaultValue);
        }

        public static string getProperty(this Dictionary<string, string> props, string key)
        {
            return props[key];
        }
    }
}
